package com.atguigu.spzx.manager.service.Impl;

import cn.hutool.core.date.DateUtil;
import com.atguigu.spzx.manager.service.OrderInfoService;
import com.atguigu.spzx.manager.service.OrderStatisticsService;
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: OrderInfoServiceImpl
 * Package: com.atguigu.spzx.manager.service.Impl
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/7 17:46
 * @Version 1.0
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoService {
    @Resource
    private OrderStatisticsService orderStatisticsService;
    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        List<OrderStatistics> orderStatisticsList = orderStatisticsService.getOrderStatisticsData(orderStatisticsDto);
        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        ArrayList<String> dateList = new ArrayList<>();
        ArrayList<BigDecimal> amountList = new ArrayList<>();
        orderStatisticsVo.setDateList(dateList);
        orderStatisticsVo.setAmountList(amountList);
        if(CollectionUtils.isEmpty(orderStatisticsList)){
            return null;
        }
        for (OrderStatistics orderStatistics : orderStatisticsList) {
            orderStatisticsVo.getDateList().add(DateUtil.format(orderStatistics.getOrderDate(),new SimpleDateFormat("yyyy-MM-dd")));
            orderStatisticsVo.getAmountList().add(orderStatistics.getTotalAmount());
        }
        return orderStatisticsVo;
    }
}
